/*
package com.example.leetcode.shopping;

import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.Date;

public class JingDong {


    public static void main(String[] args) throws Exception{

        //准备驱动
        System.setProperty("webdriver.chrome.driver","D:\\test2\\chromedriver.exe");


        //1、打开浏览器
        ChromeDriver browser = new ChromeDriver();
        Actions actions = new Actions(browser);

        //2、输入网址
        browser.get("https://www.jd.com");
        Thread.sleep(3000);

        //3、点击登录
        browser.findElement(By.linkText("你好，请登录")).click();
        Thread.sleep(6000);

//        //4、扫码登录，线程休息5秒
//        browser.findElement(By.className("icon-qrcode")).click();//扫码登录
//        Thread.sleep(5000);

        //5、进入购物车页面
        // https://cart.taobao.com/cart.htm
        browser.get("https://cart.jd.com/cart_index");
        Thread.sleep(4000);

        //6、点击选择第一个按钮
        // //*[@id="cart-body"]/div[2]/div[5]/div/div[2]/div/div/div/div[2]/div[1]/div[1]/input
        //*[@id="cart-body"]/div[2]/div[4]/div[1]/div/input
        // //*[@id="5394609"]/div[1]/div[1]/div/input
        // //*[@id="cart-body"]/div[2]/div[5]/div[1]/div/input
        // browser.findElement(By.xpath("//*[@id=\"J_Order_s_2214069938125_1\"]/div[1]/div/div/label")).click();
        //*[@id="cart-body"]/div[2]/div[5]/div[1]/div/input
        //*[@id="cart-body"]/div[2]/div[6]/div[1]/div/input
        //*[@id="cart-body"]/div[2]/div[5]/div[1]/div/input
        // browser.findElement(By.className("select-all")).click();
        // //*[@id="J_Order_s_2214735940849_1"]
        // //*[@id="J_Order_s_2214735940849_1"]
        //*[@id="J_Order_s_2599134047_1"]


        //7、循环检查结算按钮，如果倒计时结束，迅速点击
        //0、设置秒杀时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse("2022-12-22 20:30:00");
        Date endTime = sdf.parse("2022-12-22 20:31:00");
        while (true){
            //当前时间
            Date now = new Date();
//            if (now.after(endTime)) {
//                System.out.println("超过了时间");
//                break;
//            }
            if(now.after(date) || now.equals(date)){
                //*[@id="cart-body"]/div[2]/div[4]/div[1]/div/input
                browser.findElement(By.xpath("//*[@id=\"cart-body\"]/div[2]/div[4]/div[1]/div/input")).click();
                if(browser.findElement(By.linkText("去结算")).isEnabled()){
                    browser.findElement(By.linkText("去结算")).click();
                    // 下单
                    dealOrder(browser,endTime);
                    System.out.println("结算成功");
                    break;
                }

            }
        }
        ////*[@id="submitOrderPC_1"]/div/a[2]
        //      browser.findElement(By.linkText("提交订单")).click();
        // //*[@id="submitOrderPC_1"]/div/a[2]
//        browser.findElement(By.xpath("//*[@id=\"submitOrderPC_1\"]/div[1]/div/div/label")).click();
//        browser.get("https://buy.tmall.com/order/confirm_order.htm?spm=a1z0d.6639537.0.0.undefined");
//        browser.findElement(By.linkText("提交订单")).click();
        System.out.println("抢购成功");
    }


    private static void dealOrder(ChromeDriver browser, Date endTime) {
        // https://buy.tmall.com/order/confirm_order.htm?spm=a1z0d.6639537.0.0.undefined
        // https://buy.tmall.com/order/confirm_order.htm?spm=a1z0d.6639537.0.0.undefined
        // https://buy.tmall.com/order/confirm_order.htm?spm=a1z0d.6639537.0.0.undefined
        browser.get("https://trade.jd.com/shopping/order/getOrderInfo.action");
        while (true) {
            try {
//                Date date = new Date();
//                if (date.after(endTime)) {
//                    break;
//                }
//                browser.findElement(By.linkText("提交订单")).click();
                browser.findElement(By.xpath("//*[@id=\"order-submit\"]")).click();
                break;
            } catch (Exception e) {
                System.out.println("没有提交订单按钮");
            }
        }
    }
}
*/
